
#include "userinit.h"

void System_CLK_Init(void)
{
	FL_RCC_RCHF_Enable();

    FL_RCC_RCHF_SetFrequency(FL_RCC_RCHF_FREQUENCY_24MHZ);
    FL_RCC_RCHF_WriteTrimValue(RCHF24M_TRIM);
    FL_FLASH_SetReadWait(FLASH, FL_FLASH_READ_WAIT_0CYCLE);      // <24M,0 WAIT CYCLE

    FL_RCC_SetSystemClockSource(FL_RCC_SYSTEM_CLK_SOURCE_RCHF);
    FL_RCC_SetAHBPrescaler(FL_RCC_AHBCLK_PSC_DIV1);
    FL_RCC_SetAPB1Prescaler(FL_RCC_APB1CLK_PSC_DIV1);
    FL_RCC_SetAPB2Prescaler(FL_RCC_APB2CLK_PSC_DIV1);
}

void BaseTimeInit(void)
{
    FL_ATIM_InitTypeDef    TimerBaseInitStruct;

    TimerBaseInitStruct.clockSource = FL_RCC_ATIM_CLK_SOURCE_APB2CLK;
    TimerBaseInitStruct.prescaler = 24 - 1;
    TimerBaseInitStruct.counterMode = FL_ATIM_COUNTER_DIR_UP;
    TimerBaseInitStruct.autoReload = 5000;	// 5ms
    TimerBaseInitStruct.autoReloadState = FL_DISABLE;
    TimerBaseInitStruct.clockDivision = FL_ATIM_CLK_DIVISION_DIV1;
    TimerBaseInitStruct.repetitionCounter = 0;

    FL_ATIM_Init(ATIM, &TimerBaseInitStruct);
    FL_ATIM_ClearFlag_Update(ATIM);
    FL_ATIM_EnableIT_Update(ATIM);

	FL_NVIC_ConfigTypeDef    InterruptConfigStruct;

    InterruptConfigStruct.preemptPriority = 0x00;
    FL_NVIC_Init(&InterruptConfigStruct, ATIM_IRQn);

    //使能ATIM
    FL_ATIM_Enable(ATIM);

}

void GPIO_Init(void)
{
	
}


void UserInit(void)
{
	System_CLK_Init();
	BaseTimeInit();

	GPIO_Init();
}

